DocumentPicker
The DocumentPicker class provides an interface to the iOS document picker, allowing users to select files or directories and export files from within the Files app. This is useful for scripts that need to access user files, share content, or organize resources in a specified directory.
Type Definitions
PickFilesOption
Options for configuring file selection with pickFiles.
-
initialDirectory(optional)- Type:
string - Description: Specifies the initial directory that the document picker displays.
- Type:
-
types(optional)- Type:
string[] - Description: An array of uniform type identifiers (UTIs) for the document picker to display. For more details, see Uniform Type Identifiers.
- Type:
-
shouldShowFileExtensions(optional)- Type:
boolean - Description: Indicates if file extensions should be visible. Defaults to
true.
- Type:
-
allowsMultipleSelection(optional)- Type:
boolean - Description: Allows selecting multiple files. Defaults to
false.
- Type:
ExportFilesOptions
Options for exporting files using exportFiles.
-
initialDirectory(optional)- Type:
string - Description: Specifies the initial directory that the document picker displays.
- Type:
-
files- Type:
Array<{ data: Data; name: string }> - Description: An array of files to be exported. Each file object must contain:
data: The file data.name: The file name.
- Type:
Class Methods
DocumentPicker.pickFiles(options?: PickFilesOption): Promise<string[]>
Allows users to pick files from the Files app.
Parameters
options(optional):PickFilesOption- Configuration options for file selection.
Returns
- A promise that resolves with an array of file paths (
string[]).
Example
DocumentPicker.pickDirectory(initialDirectory?: string): Promise<string | null>
Allows users to pick a directory from the Files app.
Parameters
initialDirectory(optional):string- The initial directory that the document picker displays.
Returns
- A promise that resolves with the selected directory path as a
string, ornullif the user canceled the picker.
Example
DocumentPicker.exportFiles(options: ExportFilesOptions): Promise<string[]>
Exports files to the Files app.
Parameters
options:ExportFilesOptions- Configuration options for file export, including file data and names.
Returns
- A promise that resolves with an array of exported file paths (
string[]).
Example
DocumentPicker.stopAcessingSecurityScopedResources(): void
Relinquishes access to security-scoped resources, like files or directories accessed via the document picker. Use this method when you no longer need access to these resources to ensure your app manages resources efficiently.
